summaryrefslogtreecommitdiffstats
path: root/src/android/app/src/main/java/org/citra/citra_emu/features/settings/model/view/SingleChoiceSetting.java
blob: ee9d225d603f14cae1af34ea0a3b5bfdf70638b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package org.citra.citra_emu.features.settings.model.view;

import org.citra.citra_emu.features.settings.model.IntSetting;
import org.citra.citra_emu.features.settings.model.Setting;

public final class SingleChoiceSetting extends SettingsItem {
    private int mDefaultValue;

    private int mChoicesId;
    private int mValuesId;

    public SingleChoiceSetting(String key, String section, int titleId, int descriptionId,
                               int choicesId, int valuesId, int defaultValue, Setting setting) {
        super(key, section, setting, titleId, descriptionId);
        mValuesId = valuesId;
        mChoicesId = choicesId;
        mDefaultValue = defaultValue;
    }

    public int getChoicesId() {
        return mChoicesId;
    }

    public int getValuesId() {
        return mValuesId;
    }

    public int getSelectedValue() {
        if (getSetting() != null) {
            IntSetting setting = (IntSetting) getSetting();
            return setting.getValue();
        } else {
            return mDefaultValue;
        }
    }

    /**
     * Write a value to the backing int. If that int was previously null,
     * initializes a new one and returns it, so it can be added to the Hashmap.
     *
     * @param selection New value of the int.
     * @return null if overwritten successfully otherwise; a newly created IntSetting.
     */
    public IntSetting setSelectedValue(int selection) {
        if (getSetting() == null) {
            IntSetting setting = new IntSetting(getKey(), getSection(), selection);
            setSetting(setting);
            return setting;
        } else {
            IntSetting setting = (IntSetting) getSetting();
            setting.setValue(selection);
            return null;
        }
    }

    @Override
    public int getType() {
        return TYPE_SINGLE_CHOICE;
    }
}